from django.shortcuts import render

from goods.models import GoodsChannel, GoodsCategory
def get_categories():
    channels = GoodsChannel.objects.order_by('group_id', 'sequence')
    categories ={}
    for channel in channels:
        if channel.group_id not in categories:
            categories[channel.group_id]={
                'channels':[],
                'sub_cats':[]
            }
        categories[channel.group_id]['channels'].append({
            'url': channel.url,
            'name': channel.category.name
            # channels
        })
        category2 = channel.category.subs.all()
        for cat2 in category2:
            categories[channel.group_id]['sub_cats'].append({
                # 'url': channel.url,
                'name': cat2.name,
                'sub_cats': cat2.subs.all()
            })
    return categories


def get_breadcrumb(category3): # 获取三级类别

    # 面包屑导航  parent什么鬼
    category2 = category3.parent
    category1 = category2.parent
    breadcrumb = {
        'cat1':category1,
        'cat2':category2,
        'cat3':category3
    }
    return  breadcrumb